package br.com.lambdacore.iterator;

import java.util.Collection;
import java.util.List;
import java.util.Random;
import java.util.Set;

import br.com.lambdacore.collection.CollectionsUtil;
import br.com.lambdacore.iterator.impl.IntegerRange;
import br.com.lambdacore.iterator.impl.LongRange;

public class Range {

	public static int randomInRange(int end) {
		return randomInRange(0, end);
	}

	public static int randomInRange(int start, int end) {
		Random random = new Random();
		int position = random.nextInt(end - start + 1);
		return start + position;
	}

	public static Iterable<Integer> range(Collection<?> end) {
		return range(0, end);
	}

	public static Iterable<Integer> range(int end) {
		return range(0, end);
	}

	public static Iterable<Integer> range(int start, Collection<?> end) {
		return new IntegerRange(start, end.size());
	}

	public static Iterable<Integer> range(int start, int end) {
		return new IntegerRange(start, end);
	}

	public static Iterable<Integer> range(int start, Object[] end) {
		return new IntegerRange(start, end.length);
	}

	public static Iterable<Long> range(long end) {
		return range(0, end);
	}

	public static Iterable<Long> range(long start, long end) {
		return new LongRange(start, end);
	}

	public static Iterable<Integer> range(Object[] end) {
		return range(0, end);
	}

	public static List<Integer> rangeList(int end) {
		return rangeList(0, end);
	}

	public static List<Integer> rangeList(int start, int end) {
		List<Integer> list = CollectionsUtil.arrayList();
		for (Integer integer : range(start, end)) {
			list.add(integer);
		}
		return list;
	}

	public static Set<Integer> rangeSet(int end) {
		return rangeSet(0, end);
	}

	public static Set<Integer> rangeSet(int start, int end) {
		Set<Integer> set = CollectionsUtil.hashSet();
		for (Integer integer : range(start, end)) {
			set.add(integer);
		}
		return set;
	}
}
